//2009/08/08 00:19:04
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

class CalendarRecycle
{
public:
    int useAgain(int year)
    {
		int count = 0;
		for(int i = year + 1;; i++)
		{
			if(isleap(i)) count++;
			if((i + count - year) % 7 == 0 && isleap(year) == isleap(i))
				return i;
		}
		return 0;
    }
private:
    bool isleap(int year)
    {
		if(year % 4 ==0)
		{
			if(year % 100 != 0 || (year % 100 == 0 && year % 400 == 0))
				return true;
		}
		return false;
    }
};
